package com.mfnote.adapter;

import java.util.ArrayList;
import java.util.HashMap;
import com.mfnote.view.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
/**
 * 选择框适配器
 * @author ZHF
 *
 */
public class CheckBoxAdapter extends BaseAdapter{
	//填充数据的list
	private ArrayList<HashMap<String,Object>> list;
	//上下文
	private Context context;
	//用来导入布局
	private LayoutInflater inflater = null;
	//构造器
	public CheckBoxAdapter(ArrayList<HashMap<String, Object>> list, Context context) {
		this.list = list;
		this.context = context;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}


	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		
		if(convertView == null) {
			//获得ViewHolder对象
			holder = new ViewHolder();
			//导入布局并赋值给convertView
			convertView = inflater.inflate(R.layout.writebatchdelete_listview_item, null);
			holder.tv_title = (TextView) convertView.findViewById(R.id.writebatchdelete_lv_title);
			holder.tv_time = (TextView) convertView.findViewById(R.id.writebatchdelete_lv_time);
			holder.cb = (CheckBox) convertView.findViewById(R.id.writebatchdelete_checkbox);
			
			//为View设置标签
			convertView.setTag(holder);
		} else {
			//取出holder
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.tv_time.setText(list.get(position).get("time").toString());
		holder.tv_title.setText(list.get(position).get("title").toString());
		holder.cb.setChecked(Boolean.parseBoolean(list.get(position).get("flag").toString()));
//		if(holder.cb.isClickable() == true) {
//			holder.cb.setBackgroundResource(R.drawable.check_on);
//		} else {
//			holder.cb.setBackgroundResource(R.drawable.check_off);
//		}
		
		return convertView;
	}
	
	public  class ViewHolder {
			TextView tv_title;
			TextView tv_time;
			public CheckBox cb;
		}
}
